Telegram Group & Telegram Channel
๐Ÿ’ช #tip
Functions and built-ins used in `if` or ternary (`?`) blocks

An important change to the way conditional statement blocks are evaluated was introduced with v4 of Pine. Many coders are not aware of it or do not understand its implications. This User Manual section explains the change and provides a list of exceptions for functions/built-ins which are NOT affected by the constraints. We'll explain what's happening here, and how to avoid the problems caused by code that does not take the change into account.

This is what's happening:
๐Ÿ”ท 1. Starting in Pine v4, both blocks of conditional statements are no longer executed on every bar. By "both blocks", we mean the part executed when the conditional expression evaluates to true, and the one (if it exists) to be executed when the expression evaluates to false.
๐Ÿ”ท 2. Many functions/built-ins need to execute on every bar to return correct results. Think of a rolling average like sma() or a function like highest(). If they miss values along the way, it's easy to see how they won't calculate properly.

This is the PineCoders "If Law":
๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ
Whenever an if or ternary's (?) conditional expression can be evaluated differently bar to bar, all functions used in the conditional statement's blocks not in the list of exceptions need to be pre-evaluated prior to entry in the if statement, to ensure they are executed on each bar.
๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ

While this can easily be forgotten in the creative excitement of coding your latest idea, you will save yourself lots of pain by understanding and remembering this. This is a major change from previous versions of Pine. It has far-reaching consequences and not structuring code along these lines can have particularly pernicious consequences because the resulting incorrect behavior is sometimes discrete (appearing only here and there) and random.

To avoid problems, you need to be on the lookout for 2 conditions:
๐Ÿ”ท Condition A)
A conditional expression that can only be evaluated with incoming, new bar information (i.e., using series variables like close). This excludes expressions using values of literal, const, input or simple forms because they do not change during the script's execution, and so when you use them, the same block in the if statement is guaranteed to execute on every bar. [Read this if you are not familiar with Pine forms and types.]
๐Ÿ”ท Condition B)
When condition A is met, and the if block(s) contain(s) functions or built-ins NOT in the list of exceptions, i.e., which require evaluation on every bar to return a correct result, then condition B is also met.

In this FAQ & Code entry you will see an example where an apparently inoffensive built-in like vwap is used in a ternary. vwap is not in the list of exceptions, and so when condition A is realized, it will require evaluation prior to entry in the if block. You can flip between 3 modes: #1 where condition A is fulfilled and #2 and #3 where it is not. You will see how the unshielded value ("upVwap2" in the thick line) will produce incorrect results when mode 1 is used.



tg-me.com/PineCodersSquawkBox/16
Create:
Last Update:

๐Ÿ’ช #tip
Functions and built-ins used in `if` or ternary (`?`) blocks

An important change to the way conditional statement blocks are evaluated was introduced with v4 of Pine. Many coders are not aware of it or do not understand its implications. This User Manual section explains the change and provides a list of exceptions for functions/built-ins which are NOT affected by the constraints. We'll explain what's happening here, and how to avoid the problems caused by code that does not take the change into account.

This is what's happening:
๐Ÿ”ท 1. Starting in Pine v4, both blocks of conditional statements are no longer executed on every bar. By "both blocks", we mean the part executed when the conditional expression evaluates to true, and the one (if it exists) to be executed when the expression evaluates to false.
๐Ÿ”ท 2. Many functions/built-ins need to execute on every bar to return correct results. Think of a rolling average like sma() or a function like highest(). If they miss values along the way, it's easy to see how they won't calculate properly.

This is the PineCoders "If Law":
๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ
Whenever an if or ternary's (?) conditional expression can be evaluated differently bar to bar, all functions used in the conditional statement's blocks not in the list of exceptions need to be pre-evaluated prior to entry in the if statement, to ensure they are executed on each bar.
๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ๐Ÿ”ธ

While this can easily be forgotten in the creative excitement of coding your latest idea, you will save yourself lots of pain by understanding and remembering this. This is a major change from previous versions of Pine. It has far-reaching consequences and not structuring code along these lines can have particularly pernicious consequences because the resulting incorrect behavior is sometimes discrete (appearing only here and there) and random.

To avoid problems, you need to be on the lookout for 2 conditions:
๐Ÿ”ท Condition A)
A conditional expression that can only be evaluated with incoming, new bar information (i.e., using series variables like close). This excludes expressions using values of literal, const, input or simple forms because they do not change during the script's execution, and so when you use them, the same block in the if statement is guaranteed to execute on every bar. [Read this if you are not familiar with Pine forms and types.]
๐Ÿ”ท Condition B)
When condition A is met, and the if block(s) contain(s) functions or built-ins NOT in the list of exceptions, i.e., which require evaluation on every bar to return a correct result, then condition B is also met.

In this FAQ & Code entry you will see an example where an apparently inoffensive built-in like vwap is used in a ternary. vwap is not in the list of exceptions, and so when condition A is realized, it will require evaluation prior to entry in the if block. You can flip between 3 modes: #1 where condition A is fulfilled and #2 and #3 where it is not. You will see how the unshielded value ("upVwap2" in the thick line) will produce incorrect results when mode 1 is used.

BY PineCoders Squawk Box


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/PineCodersSquawkBox/16

View MORE
Open in Telegram


PineCoders Squawk Box Telegram | DID YOU KNOW?

Date: |

Chinaโ€™s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. Chinaโ€™s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the countryโ€™s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, Chinaโ€™s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of Chinaโ€™s most coveted overseas-listed companies back to the country.

Telegram Be The Next Best SPAC

I have no inside knowledge of a potential stock listing of the popular anti-Whatsapp messaging app, Telegram. But I know this much, judging by most people I talk to, especially crypto investors, if Telegram ever went public, people would gobble it up. I know I would. Iโ€™m waiting for it. So is Sergei Sergienko, who claims he owns $800,000 of Telegramโ€™s pre-initial coin offering (ICO) tokens. โ€œIf Telegram does a SPAC IPO, there would be demand for this issue. It would probably outstrip the interest we saw during the ICO. Why? Because as of right now Telegram looks like a liberal application that can accept anyone - right after WhatsApp and others have turn on the censorship,โ€ he says.

PineCoders Squawk Box from sa


Telegram PineCoders Squawk Box
FROM USA